let time: NodeJS.Timeout | null = null

export function debounce(func: Function,delay:number){
  clearTimeout(time as any)
  time = setTimeout(()=>{
    func()

  },delay)
}

export function newDebounce(fn: Function,wait:number,immediate = false) {
  let timer: any = null
  return function (this:void,...args: any[]){
    timer && clearTimeout(timer)
    if(immediate) {
      fn && fn.apply(this,args)
      immediate = false
    } else {
      timer = setTimeout(()=>{
        fn && fn.apply(this,args)
      },wait)
    }
  }
}
